package com.yc.wxcontroller;

import com.yc.service.impl.ScheduleServiceImpl;
import com.yc.service.impl.StudentInfoServiceImpl;
import com.yc.service.impl.TeacherDelaysServiceImpl;
import com.yc.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author mqm
 * @version 1.0
 * @date 2023/7/9 20:51
 */
@RestController
public class WXTeacherDelaysController {

    @Resource
    private StudentInfoServiceImpl studentInfoService;
    @Resource
    private TeacherDelaysServiceImpl teacherDelaysService;
    @Resource
    private ScheduleServiceImpl scheduleService;

    @ApiOperation("添加举报信息")
    @PostMapping("wx/reportTea")
    public Result insertTeaDelays( @RequestParam(value = "remarks" ,required = true) String  remarks,
                                  @RequestParam(value = "classtime",required = true) String classTime, @RequestParam(value = "stuid",required = true)String stuid
               ,@RequestParam("date") String date){

        //查出举报人班级Id
        int classId = studentInfoService.queriCid(stuid);
        //根据课程名和班级查出teacherId
        Integer teacherId = teacherDelaysService.queryTeaID(classId, classTime,date);
        if (teacherId==null){
            return Result.error("请添加正确信息");
        }
        //查出课表ID
        Integer scheduleId = scheduleService.queryscheduleid(teacherId, classTime,date,classId);
        if (scheduleId==null){
            return Result.error("请添加正确信息"); }
        //添加数据
        int status=0;
        Result result = teacherDelaysService.insertTeaDelays(teacherId, scheduleId, date, stuid,classId,status, remarks);
        return  result;
    }

    /**
     * 查出举报老师迟到数据
     * @param stuid
     * @return
     */
    @ApiOperation("查出举报老师迟到数据")
    @PostMapping("wx/queryInfoTea")
    public Result queryinfoTea(@RequestParam("stuid") String stuid){
        List<Map<String, Object>> list = teacherDelaysService.queryInfoTea(stuid);
        return Result.success(list);
    }
    @ApiOperation("上报老师迟到信息")
    @PostMapping("wx/updateTeaStatus")
    public Result updateTeaStatus(@RequestParam("id") int id){
        Result result = teacherDelaysService.updateStatus(id);
        return result;
    }
    @ApiOperation("驳回老师迟到信息")
    @PostMapping("wx/updateTeaStatusFalse")
    public Result updateTeaStatusFalse(@RequestParam("id") int id){
        Result result = teacherDelaysService.updateStatusFalse(id);
        return result;
    }
    @ApiOperation("查询已处理老师迟到数据总数")
    @PostMapping("wx/querytotal")
    public Result queryTotal(@RequestParam("date")String date){
        int total = teacherDelaysService.queryTotal(date);
        return Result.success(total);
    }

    @ApiOperation("领导查询已提交的老师迟到信息")
    @PostMapping("wx/managerquery")
    public Result managerquery(@RequestParam("date")String date,@RequestParam("page")int page){
        List<Map<String, Object>> list = teacherDelaysService.managerquery(page,date);
        return Result.success(list);
    }
    @ApiOperation("查询未处理的举报老师迟到信息")
    @PostMapping("wx/queryCount")
    public Result queryCount( @RequestParam("stuid") String stuid){
        int count = teacherDelaysService.queryCount(stuid);
        return Result.success(count);
    }

}
